package com.cll.learn.rpc.provider.service;

import com.cll.learn.rpc.api.entity.User;
import com.cll.learn.rpc.api.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 描述信息:
 * 实现API模块提供的接口
 * @author CLL
 * @version 1.0
 * @date 2020/9/14 15:48
 */
@Service
public class UserServiceImpl implements UserService {

    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    /**
     * TODO 将来修改为从数据库查询数据
     * 根据查询参数查询用户列表
     * @param user  查询参数
     * @return  用户列表
     */
    @Override
    public List<User> select(User user) {
        logger.info("===>>> select");
        List<User> resultList = new ArrayList<>(2);
        if (null == user || null == user.getId()) {
            resultList.add(new User(1, "cll", "陈林林", new Date()));
            resultList.add(new User(2, "yl", "杨柳", new Date()));
        } else if (0 == (user.getId() % 2)) {
            resultList.add(new User(1, "cll", "陈林林", new Date()));
            resultList.add(new User(2, "yl", "杨柳", new Date()));
        } else {
            resultList.add(new User(1, "cll", "陈林林", new Date()));
        }
        return resultList;
    }
}